package com.example.checkboxpj;

import java.util.jar.Attributes.Name;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	EditText edt, edc;
	CheckBox cbbao, cbcode, cbbanh;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	     edt = (EditText) findViewById(R.id.edname);
		 edc = (EditText) findViewById(R.id.edcode);
		 cbbao = (CheckBox) findViewById(R.id.cbbao);
		 cbcode = (CheckBox) findViewById(R.id.cbcode);
		 cbbanh = (CheckBox) findViewById(R.id.cbbanh);
		Button btn = (Button) findViewById(R.id.btgtt);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				doShowInformation();	
			}
		});
			
	}
public void doShowInformation()
{
	//kiem tra tinh hop le 
	String ten = edt.getText()+""; ten = ten.trim();
	if(ten.length()<3)
	{
		edt.requestFocus();
		edt.selectAll();
		Toast.makeText(this, "Ten phai>=3 ki tu", Toast.LENGTH_LONG).show();
		return;
	}
	//kiem tra CMND
	String cm = edc.getText()+""; cm = cm.trim();
	if(cm.length()!=9)
	{
		edc.requestFocus();
		edc.selectAll();
		Toast.makeText(this, "CMND fai dung 9 ki tu", Toast.LENGTH_LONG).show();
		return;
	}
	//kiem tra bang cap
	String bang ="";
	RadioGroup gr = (RadioGroup) findViewById(R.id.radioGroup1);
	int id = gr.getCheckedRadioButtonId();
	if(id==-1)
	{
		Toast.makeText(this, "Phai chon bang cap", Toast.LENGTH_LONG).show();
		return;
	}
	RadioButton rad = (RadioButton) findViewById(id);
	bang = rad.getText()+"";
	//kiem tra so thich
	String sothich ="";
	if(cbbanh.isChecked())
		sothich+=cbbanh.getText()+"\n";
	if(cbbao.isChecked())
		sothich+=cbbao.getText()+"\n";
	if(cbcode.isChecked())
		sothich+=cbcode.getText()+"\n";
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	builder.setTitle("Thong tin ca nhan");
	builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			dialog.cancel();
		}
	});
	//tao noi dung
	String msg = ten + "\n";
	msg +=cm+"\n";
	msg+=bang+"\n";
	msg+=sothich;
	msg+="----------\n";
	builder.setMessage(msg);//thiet lap noi dung
	builder.create().show();//hien thi dialog
}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
